package com.ruoyi.tjfx.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tjfx.domain.TbTjfxQynhzb;
import com.ruoyi.tjfx.service.ITbTjfxQynhzbService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 企业各能耗占比Controller
 *
 * @author ruoyi
 * @date 2023-11-12
 */
@RestController
@RequestMapping("/tjfx/qynhzb")
public class TbTjfxQynhzbController extends BaseController
{
    @Autowired
    private ITbTjfxQynhzbService tbTjfxQynhzbService;

    /**
     * 查询企业各能耗占比列表
     */
    @PreAuthorize("@ss.hasPermi('tjfx:qynhzb:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbTjfxQynhzb tbTjfxQynhzb)
    {
        startPage();
        List<TbTjfxQynhzb> list = tbTjfxQynhzbService.selectTbTjfxQynhzbList(tbTjfxQynhzb);
        return getDataTable(list);
    }

    /**
     * 导出企业各能耗占比列表
     */
    @PreAuthorize("@ss.hasPermi('tjfx:qynhzb:export')")
    @Log(title = "企业各能耗占比", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbTjfxQynhzb tbTjfxQynhzb)
    {
        List<TbTjfxQynhzb> list = tbTjfxQynhzbService.selectTbTjfxQynhzbList(tbTjfxQynhzb);
        ExcelUtil<TbTjfxQynhzb> util = new ExcelUtil<TbTjfxQynhzb>(TbTjfxQynhzb.class);
        util.exportExcel(response, list, "企业各能耗占比数据");
    }

    /**
     * 获取企业各能耗占比详细信息
     */
    @PreAuthorize("@ss.hasPermi('tjfx:qynhzb:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbTjfxQynhzbService.selectTbTjfxQynhzbById(id));
    }

    /**
     * 新增企业各能耗占比
     */
    @PreAuthorize("@ss.hasPermi('tjfx:qynhzb:add')")
    @Log(title = "企业各能耗占比", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbTjfxQynhzb tbTjfxQynhzb)
    {
        return toAjax(tbTjfxQynhzbService.insertTbTjfxQynhzb(tbTjfxQynhzb));
    }

    /**
     * 修改企业各能耗占比
     */
    @PreAuthorize("@ss.hasPermi('tjfx:qynhzb:edit')")
    @Log(title = "企业各能耗占比", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbTjfxQynhzb tbTjfxQynhzb)
    {
        return toAjax(tbTjfxQynhzbService.updateTbTjfxQynhzb(tbTjfxQynhzb));
    }

    /**
     * 删除企业各能耗占比
     */
    @PreAuthorize("@ss.hasPermi('tjfx:qynhzb:remove')")
    @Log(title = "企业各能耗占比", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbTjfxQynhzbService.deleteTbTjfxQynhzbByIds(ids));
    }
}
